/**
 * Created by lgc on 2017/10/28.
 */
import {localLogin} from '../../service'
import * as types from '../mutation-types'
import Cookies from 'js-cookie';
import api from '../../service/getData'
import axios from '../../http'


// initial state
const state = {
  items:[]
}

// getters
const getters = {
}
export const LocalLogin = ({ commit }) => {

}
// actions
const actions = {
  LocalLogin({ commit },userInfo){
    return new Promise((resolve, reject) => {
      axios.post(api.login_form, userInfo).then(response => {
        if(response.data.rspCode == "000000"){
          let token = JSON.parse(response.data.data).access_token;
          commit(types.LOGIN, token);
          resolve()
        }else {
          reject(response.data.rspMsg)
        }
      }).catch(error => {
        reject(error)
      })
    })
  }
}

// mutations
const mutations = {
  [types.FAILURE_GET_LOGINS](state){
    console.info("error");
    state.items = []

  },
  [types.SUCCESS_GET_LOGINS](state,data){
    console.info("ok");
    console.info(data);
    state.items = data;
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
